//
//  Home_headerView.m
//  HappyRent
//
//  Created by CoderYee on 2017/3/31.
//  Copyright © 2017年 内圈科技. All rights reserved.
//

#import "Home_headerView.h"

@interface XRButtonTopImageButton : UIView
-(instancetype)initWithFrame:(CGRect)frame;
@property(nonatomic,retain)UIImageView   *imageView;
@property(nonatomic,retain)UILabel       *titlelable;

@end

@implementation XRButtonTopImageButton

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame])
    {
        [self addOwnView];
    }
    
    return self;
}
-(void)addOwnView
{
    _titlelable=[[UILabel alloc] init];
    _titlelable.font=[UIFont systemFontOfSize:15];
    _titlelable.textAlignment=NSTextAlignmentCenter;
    _titlelable.textColor=kBlackColor;
    _titlelable.text=@"每日任务";
    [self addSubview:_titlelable];
    [_titlelable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).with.offset(-5);
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.height.mas_equalTo(21);
    }];
    _imageView=[[UIImageView alloc] init];
    [self addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(0);
        make.centerX.equalTo(self);
        make.bottom.equalTo(_titlelable.mas_top);
        make.width.mas_equalTo(_imageView.mas_height);
    }];
}
@end

@interface Home_headerView ()


@end

@implementation Home_headerView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self=[super initWithFrame:frame]) {
        
        [self setBackgroundColor:kWhiteColor];
        [self addOwnView];
        [self layOutOwnView];
        
    }
    return self;
}

-(void)addOwnView{
    
    _backImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kMainScreenWidth, self.height*0.72)];
    _backImageView.contentMode=UIViewContentModeScaleAspectFill;
    _backImageView.clipsToBounds=YES;
    [_backImageView  setImage:[UIImage imageNamed:@"002"]];
    [self addSubview:_backImageView];
    _searchImageView=[[UIImageView alloc] init];
    [_searchImageView setImage:[UIImage imageNamed:@"搜索"]];
    [self addSubview:_searchImageView];
    
    CGFloat  margin    = 10;
    CGFloat  itemWidth = 80;
    CGFloat rowMargin=(kMainScreenWidth-20-4*itemWidth)/3.0;
    NSArray *titleArray=@[@"名宿",@"自营",@"体验",@"房产"];
    NSArray *ImageArray=@[@"儿童",@"婚纱",@"商业",@"写真"];

    for (NSInteger i=0; i<4; i++) {
        
        XRButtonTopImageButton  *item=[[XRButtonTopImageButton alloc] initWithFrame:CGRectMake((rowMargin+itemWidth)*i+margin, self.height*0.75+itemWidth*0.3, itemWidth, itemWidth)];
        [item.imageView setImage:[UIImage imageNamed:ImageArray[i]]];
        item.titlelable.text=titleArray[i];
        [self addSubview:item];
    }
}
-(void)layOutOwnView{
    
    [_searchImageView mas_makeConstraints:^(MASConstraintMaker *make){
        make.centerY.equalTo(_backImageView.mas_bottom);
        make.left.equalTo(self).with.offset(18);
        make.height.width.mas_equalTo(60);
    }];
    
}
@end
